package stock.service;

import cloudentity.model.Stock;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import stock.mapper.StockMapper;

@Service
public class StockService {
    @Autowired
    private StockMapper stockMapper;

    public Stock deduct(Integer id){
        try {
            Stock stock = this.stockMapper.selectOne(new QueryWrapper<Stock>().eq("id",id));
            if(stock!=null && stock.getCount()>0){
                stock.setCount(stock.getCount()-1);
                this.stockMapper.updateById(stock);
            }
            return stock;
        }finally {

        }
    }
}
